{% extends 'KeioStudyBundle::layout.html.twig' %}

{% block content %}
    <h2>Add package to member</h2>
    <hr />

	{% if member_is_user==0 %}
		User has not profile USER. Nothing to do here
	{% else %}
		<h3>Current packages:</h3>
		{% for pkg in packageY %}
			<p>{{ pkg.name }} (description: {{ pkg.description }})
		{% endfor %}

		<h3>Non attached packages:</h3>

		<form name="name_for_enable_submit" action="{{ path('admin_user_addpackagetomember', {'member_id': memberid}) }}" method="POST">
			{% for pkg in packageN %}
				<div id="addbaihoctopackage">
					<br><input type="checkbox" name="package[]" value="{{ pkg.id }}" onchange="checkform()">
					{{ pkg.name }} (description: {{ pkg.description }})
				</div>
			{% endfor %}
			<br><input id="submitbutton" type="submit" disabled="disabled" value="Add"><br>
		</form>

	{% endif %}

	<a href="{{ path('admin_user_member') }}">
        Back to list of members
    </a>

{% endblock %}


{% block morejavascripts %}
		<script type="text/javascript" language="javascript">
		    function checkform()
		    {
		    	var f = document.forms["name_for_enable_submit"].elements;
		    	var cansubmit = true;
		        var x = 0;
		        for (var i = 0; i < f.length; i++) {
		        	if (f[i].checked){
		            	x = x + 1;
		            }
		        }
		        if (x == 0) cansubmit = false;
	            document.getElementById('submitbutton').disabled = !cansubmit;
		    }
		</script>
{% endblock %}